import { system as http } from '@zh/common-utils/http'
import { store } from '../../store'

export { http }

/**
 * 获取所有菜单
 */
export function getAll (params) {
  return http.get('/system/menu/all', {
    data: params
  })
}

/**
 * 初始化菜单
 */
export function initMenuLevel () {
  return http.get('/system/menu/updateMenuLevelCode')
}
/**
 * 删除菜单
 * @param {String} menuId
 */
export function del (menuId) {
  return http.delete('/system/menu/delete', { data: { id: menuId } })
}

export function deleteById (menuId) {
  return http.post('/system/menu/deleteById/' + menuId)
}
/**
 * 修改或删除菜单
 * @param {Object} data
 */
export function saveOrUpdate (data) {
  const url = data.id ? '/system/menu/update' : '/system/menu/save'
  return http.post(url, data)
}

/**
 * 根据ID查询菜单
 * @param {String} menuId
 */
export function getById (menuId) {
  return http.post('system/menu/getById', { id: menuId })
}

/**
 * 根据parentId查询所有上级菜单
 * @param {String} menuId
 */
export function getParentsById (parentId) {
  return http.get(`system/menu/initMenu?parentId=${parentId}`)
}

/**
 * 获取排序号
 */
export function getOrderNo (parentId) {
  return http.get(`/system/menu/getOrderNo/${parentId || ''}`)
}

/**
 * 获取应用管理列表
 */
export function getAppList (parentId) {
  return http.post('/app/sysApplication/list')
}
